package com.ost.kautilya.modeling;

public enum Periodicity implements ForecasterPeriodicity {
	HOURLY(1), DAILY(24 * HOURLY.valueInUnits()), WEEKLY(7 * DAILY.valueInUnits()), MONTHLY(DAILY.valueInUnits() * (31)), AUTO(DAILY.valueInUnits()), UNKNOWN(DAILY.valueInUnits()), QUARTERLY(
			MONTHLY.valueInUnits() * (3)), YEARLY((QUARTERLY.valueInUnits() * 4) - 1);
	private final long bd;

	private Periodicity(long bd) {
		this.bd = bd;
	}

	@Override
	public long valueInUnits() {
		return bd;
	}

	public long valueInMillis() {
		return valueInUnits() * 1000 * 60 * 60;
	}

	public static Periodicity forUnits(long units) {
		if (0 < units && units <= HOURLY.valueInUnits())
			return HOURLY;
		if (HOURLY.valueInUnits() < units && units <= DAILY.valueInUnits())
			return DAILY;
		if (DAILY.valueInUnits() < units && units <= WEEKLY.valueInUnits())
			return WEEKLY;
		if (WEEKLY.valueInUnits() < units && units <= MONTHLY.valueInUnits())
			return MONTHLY;
		if (MONTHLY.valueInUnits() < units && units <= QUARTERLY.valueInUnits())
			return QUARTERLY;
		if (QUARTERLY.valueInUnits() < units && units <= YEARLY.valueInUnits())
			return YEARLY;
		return UNKNOWN;
	}
}